package cn.tedu.dental.dental.controller;

import cn.tedu.dental.base.response.JsonResult;
import cn.tedu.dental.dental.pojo.dto.DentalQuery;
import cn.tedu.dental.dental.pojo.dto.DentalSaveParam;
import cn.tedu.dental.dental.pojo.vo.DentalVO;
import cn.tedu.dental.dental.service.DentalService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/dental")
public class DentalController {

    @Autowired
    private DentalService dentalService;


    /**
     * 查询用户方法
     *
     * @param dentalQuery
     * @return
     */
    @GetMapping("select")
    public JsonResult selectDental(DentalQuery dentalQuery) {
        log.debug("查询用户:入参dentalQuery={}", dentalQuery);
        List<DentalVO> list = dentalService.selectDental(dentalQuery);
        log.debug("查询用户:出参list={}", list);
        return JsonResult.ok(list);
    }

    @GetMapping("/selectById/{dentalId}")
    public JsonResult selectDentalById(@PathVariable Long dentalId) {
        log.debug("编辑牙况,dentalId={}", dentalId);
        List<DentalVO> list = dentalService.selectDentalById(dentalId);
        return JsonResult.ok(list);
    }

    @PostMapping("save")
    public JsonResult saveDental(DentalSaveParam dentalSaveParam){
        log.debug("保存修改的牙况,userSaveParam={}",dentalSaveParam);
        dentalService.saveDental(dentalSaveParam);
        log.debug("保存修改的牙况,userSaveParam={}",dentalSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("/delete/{dentalId}")
    public JsonResult deleteUser(@PathVariable Long dentalId){
        log.debug("删除牙况,dentalId={}",dentalId);
        dentalService.deleteDental(dentalId);
        return JsonResult.ok();
    }
}
